<?php
require_once ("include/webservice/WebServiceServer.php");

define('PRE',"hh");
define('DB',"dy");
$DB = new DB_MYSQL ();

$key = "happyeverydays";
//$enc_text = encrypt($string,$key);加密
//$dec_text = decrypt($enc_text,$key);解密
$url = $_REQUEST['u'];
//$url = decrypt($url,$key);
//明文url，如果不想要明文，就在上行去掉前面的注释
$id = $_REQUEST['id'];
$open_ip= $_SERVER["REMOTE_ADDR"];
$open_time = date("Y-m-d H:i:s");
$open_url=$_SERVER['HTTP_REFERER'] ;
$where = "where id =" .$sid;

$DB ->connect();
$sql = "update ".PRE."_send_email set open_ip = '".$open_ip."',open_time =  UNIX_TIMESTAMP('".$open_time."'),open_url='".$open_url."' ".$where;
$DB->update($sql, $dbbase);
header("Content-type: image/jpeg");
$filename=$url;
$fp=fopen($filename,"rb");
$pic1=fread($fp,filesize($filename));
fclose($fp);
$pictrue=$pic1;

echo $pictrue;


function keyED($txt,$encrypt_key)
{
$encrypt_key = md5($encrypt_key);
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
$ctr++;
}
return $tmp;
}

//加密码函数
function encrypt($txt,$key)
{
//srand((double)microtime()*1000000);
$encrypt_key = md5(rand(0,320000000));
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($encrypt_key,$ctr,1) .
(substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
$ctr++;
}
return keyED($tmp,$key);
}

//解密函数
function decrypt($txt,$key)
{
$txt = keyED($txt,$key);
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
$md5 = substr($txt,$i,1);
$i++;
$tmp.= (substr($txt,$i,1) ^ $md5);
}
return $tmp;
}

?>